package china.accountinghelper.database;

import java.util.Map;

import com.xdroid.base.SQLiteDALBase;

import android.content.ContentValues;
import android.database.Cursor;
import china.wc.tallyhelper.model.ModelExpense;

/**
 * 操作ModelExpense类的SQLiteDatabaseDAL类
 * 
 * 
 * 
 * @author 王超
 * 
 */
public class SQLiteDALModelExpense extends SQLiteDALBase<ModelExpense>
{

    public SQLiteDALModelExpense(Class<ModelExpense> pModelClass)
    {
        super(pModelClass);
    }
    
    @Override
    protected ContentValues toContentValues(ModelExpense pModelExpense)
    {
        Map<String, String> _AllFieldColumn = getFieldColumnMap();
        ContentValues _ContentValues = new ContentValues();

        for (String _FieldName : _AllFieldColumn.keySet()) {
            if ("mBookID".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelExpense.getBookID());
            } else if ("mCategoryID".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelExpense.getCategoryID());
            } else if ("mPayerID".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelExpense.getPayerID());
            } else if ("mExpenseDate".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelExpense.getExpenseDate().getTimeInMillis());
            } else if ("mCreateTime".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelExpense.getCreateTime().getTimeInMillis());
            } else if ("mComment".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelExpense.getComment());
            }
        }

        return _ContentValues;
    }

    @Override
    protected ModelExpense toModel(Cursor pCursor)
    {
        ModelExpense _ModelExpense = new ModelExpense();

        _ModelExpense.setID(pCursor.getLong(pCursor.getColumnIndexOrThrow(getPrimaryColumnName())));
        _ModelExpense.setBookID(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mBookID"))));
        _ModelExpense.setCategoryID(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mCategoryID"))));
        _ModelExpense.setPayerID(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mPayerID"))));
        _ModelExpense.setExpenseDate(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mExpenseDate"))));
        _ModelExpense.setCreateTime(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mCreateTime"))));
        _ModelExpense.setComment(pCursor.getString(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mComment"))));

        return _ModelExpense;
    }

}
